<?php
namespace App\Service\Search;

use DB;

class SearchService
{
    public static function getSearchInfo($uid,$info,$page,$offset)
    {

        $msg = DB::select("select
(select count(*) from lsj_praise_log b where b.articleid=a.id)  as praise_num,
(select count(*) from lsj_comment_log b where a.id=b.worksid) as comment_num,
(select count(*) from lsj_order b where a.id=b.article_id and b.paystatus=1) as order_num,
(select count(*) from lsj_praise_log b where b.articleid=a.id and b.uid= ?) as is_praise,
(select count(*) from lsj_order b where a.id=b.article_id and b.paystatus=1 and b.uid=?) as is_buy,
id,title,introduction,author,price,thumb,create_time,author_uid,reading,a.article_class,a.buy_class
from lsj_article a
where a.status=1 and (a.title like '%{$info}%' or key_word like '%{$info}%' or author like '%{$info}%')
and a.craw_class=0
order by a.id desc
limit ?,?",[$uid,$uid,$offset,$page]);

        return $msg;
    }
	
	public static function getSearchRecommend()
    {
        $result = DB::table('lsj_search_recommend')->get()->toArray();
        return $result;
    }
	
	public static function getXcxSearchInfo($info)
    {

        $msg = DB::select("select
(select count(*) from lsj_praise_log b where b.articleid=a.id)  as praise_num,
(select count(*) from lsj_comment_log b where a.id=b.worksid) as comment_num,
(select count(*) from lsj_order b where a.id=b.article_id and b.paystatus=1) as order_num,
id,title,introduction,author,price,thumb,create_time,author_uid,reading
from lsj_article a
where a.status=1 and (a.title like '%{$info}%' or key_word like '%{$info}%' or author like '%{$info}%')
order by a.id desc
limit 0,15");

        return $msg;
    }
}